package com.hkts.naturalgas.performance.controller;


import com.hkts.naturalgas.performance.performanceVo.FormAndItemResultVo;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.hkts.naturalgas.utils.CustomPageUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hkts.naturalgas.utils.Result;
import com.hkts.naturalgas.utils.ResultUtil;
import com.alibaba.fastjson.JSON;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.GetMapping;

import com.hkts.naturalgas.performance.service.IHkAssessmentFormService;
import com.hkts.naturalgas.performance.entity.HkAssessmentForm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * @author yck
 * @since 2020-12-16
 */
@RestController
@RequestMapping("/performance/hkAssessmentForm")
public class HkAssessmentFormController {
    private final Logger logger = LoggerFactory.getLogger(HkAssessmentFormController.class);

    @Autowired
    public IHkAssessmentFormService iHkAssessmentFormService;

    /**
     * 分页查询数据
     *
     * @param page             分页信息
     * @param hkAssessmentForm 查询条件
     * @return
     */
    @ResponseBody
    @GetMapping("/getHkAssessmentFormPageList")
    public Result<Object> getHkAssessmentFormPageList(Page<HkAssessmentForm> page, HkAssessmentForm hkAssessmentForm) {
        return ResultUtil.data(CustomPageUtils.getCustomPage(iHkAssessmentFormService.selectPage(page, hkAssessmentForm)));
    }

    /**
     * 保存和修改公用的
     *
     * @param hkAssessmentForm 传递的实体
     * @return saveOrUpdate
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hkAssessmentFormSave")
    public Result<Object> hkAssessmentFormSave(HkAssessmentForm hkAssessmentForm) {
        iHkAssessmentFormService.saveOrUpdate(hkAssessmentForm);
        return ResultUtil.success("保存成功");
    }

    /**
     * 根据id获取对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/hkAssessmentFormGetById")
    public Result<Object> hkAssessmentFormGetById(String id) {
        HkAssessmentForm byId = iHkAssessmentFormService.getById(id);
        return ResultUtil.data(byId);
    }

    /**
     * 根据id删除对象
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hkAssessmentFormDelete")
    public Result<Object> hontUserDelete(String id) {
        iHkAssessmentFormService.removeById(id);
        return ResultUtil.success("删除成功");
    }

    /**
     * 批量删除对象
     *
     * @param item 实体集合ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hkAssessmentFormBatchDelete")
    public Result<Object> deleteBatchIds(String item) {
        List<String> ids = (List<String>) JSON.parse(item);
        iHkAssessmentFormService.removeByIds(ids);
        return ResultUtil.success("删除成功");
    }

    public IHkAssessmentFormService getiHkAssessmentFormService() {
        return iHkAssessmentFormService;
    }

    public void setiHkAssessmentFormService(IHkAssessmentFormService iHkAssessmentFormService) {
        this.iHkAssessmentFormService = iHkAssessmentFormService;
    }

    /*
     * 根据流程实例ID获取表单
     *
     * */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/getHkAssessmentFormByProcessId")
    public Result<Object> getHkAssessmentFormByProcessId(String processId) throws Exception {
        List<FormAndItemResultVo> vo=iHkAssessmentFormService.getHkAssessmentFormByProcessId(processId);
        return ResultUtil.data(vo);
    }
}
